<%--
  Created by IntelliJ IDEA.
  User: 乔见东方姑娘
  Date: 2023/8/26
  Time: 21:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>部门列表页面</title>
    <script src="js/jquery-3.7.0.js"></script>
    <script>
        $(function () {
            // 全选全不选
            $("#all").click(function () {
                var status = $(this).prop("checked");
                $(".one").prop("checked", status);
                // 添加数据量
                $("#checkedCount").text($(".one:checked").length);
            });

            // 勾选
            $(".one").click(function () {
                var checkboxLength = $(".one").length;
                var checkedLength = $(".one:checked").length;
                if (checkboxLength === checkedLength) {
                    $("#all").prop("checked", true);
                } else {
                    $("#all").prop("checked", false);
                }
                // 添加数量
                $("#checkedCount").text($(".one:checked").length);
            })
            // 给button绑定点击事件
            $("#batchDelete").click(function () {
                var length = $(".one:checked").length;
                if (length === 0) {
                    alert("请选择需要删除的内容");
                } else {
                    // 提醒下：你确定要删除部门信息吗？
                    if (confirm("你确定要删除部门信息吗？")) {
                        // 通过js进行提交
                        $("#formBatch").submit();
                    }
                }
            })
        })
    </script>
</head>
<body>
<div>
        <span>
            <a href="${pageContext.request.contextPath}/addDepartment.jsp">添加部门</a>&emsp;&emsp;
        </span>

</div>
<form action="${pageContext.request.contextPath}/department/batchDeleteDepartment.action" id="formBatch" method="get">
    <table border="1" cellspacing="0">
        <caption>
            <span style="position:relative;left: -75px;">
                <button type="button" id="batchDelete">
                批量删除 <span id="checkedCount">0</span>
                </button>
            </span>
            <span>查询列表信息</span>
        </caption>

        <thead>
        <tr>
            <th><input type="checkbox" id="all"></th>
            <th>序号</th>
            <th>部门名称</th>
            <th>部门描述</th>
            <th>部门更新时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:choose>
            <c:when test="${not empty page.list}">
                <c:forEach items="${page.list}" var="department" varStatus="status">
                    <tr>
                        <td><input type="checkbox" name="checkId" class="one" value="${department.dId}"></td>
                        <td>
                            <span>${status.count}</span>
                        </td>
                        <td>
                            <span>${department.dName}</span>
                        </td>
                        <td>
                            <span>${department.dDesc}</span>
                        </td>
                        <td>
                    <span>
                        <fmt:formatDate value="${department.dTime}" pattern="MM-dd HH:mm"/>
                    </span>
                        </td>
                        <td>
                    <span>
                       <a href="${pageContext.request.contextPath}/department/toEditDepartment.action?id=${department.dId}">编辑</a>
                    </span>
                            <span>
                       <a href="${pageContext.request.contextPath}/department/deleteDepartment.action?id=${department.dId}">删除</a>
                    </span>
                        </td>
                    </tr>
                </c:forEach>
            </c:when>
            <c:otherwise>
                <tr>
                    <td colspan="6" style="text-align: center">空空如也</td>
                </tr>
            </c:otherwise>
        </c:choose>
        </tbody>
    </table>
    <div>
                <span>
                    总页码数：${page.totalPage}&emsp;
                    总数据量：${page.totalCount}
                </span> &emsp;&emsp;
        <span>
                     <c:if test="${page.currentPage > 1}">
                         <a href="${pageContext.request.contextPath}/department/pageQueryDepart2ments.action?currentPage=${page.currentPage-1}">上一页</a>
                     </c:if>
                     <c:forEach begin="${page.startPage}" end="${page.endPage}"
                                varStatus="status"><%-- startPage=1 endPage=5  --%>
                         <%--当前页页码数为红色  其他页码数为正常色--%>
                         <c:choose>
                             <c:when test="${page.currentPage == status.index}">
                                <a style="color: red;"
                                   href="${pageContext.request.contextPath}/department/pageQueryDepart2ments.action?currentPage=${status.index}">
                                        ${status.index}
                                </a>
                             </c:when>
                             <c:otherwise>
                             <a style="color: black;"
                                href="${pageContext.request.contextPath}/department/pageQueryDepart2ments.action?currentPage=${status.index}">
                                     ${status.index}
                             </a>
                             </c:otherwise>
                         </c:choose>
                     </c:forEach>
                    <c:if test="${page.currentPage ne page.totalPage}">
                        <a href="${pageContext.request.contextPath}/department/pageQueryDepart2ments.action?currentPage=${page.currentPage+1}">下一页</a>
                    </c:if>
                </span>
    </div>
</form>
</body>
</html>
